home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 37 / IOPROG_37.ISO / SOFT / Multilizer.exe / disk1 / data1.cab / data1 / [Group9]VCL Source Standard / IvDlgMod.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1999-08-12  |  25.5 KB  |  933 lines

  1. { This translator module component translates the common dialog components. }
  2.  
  3. unit IvDlgMod;
  4.  
  5. {$I IVMULTI.INC}
  6.  
  7. interface
  8.  
  9. uses
  10. {$IFDEF WIN32}
  11.   Windows,
  12. {$ELSE}
  13.   WinTypes, WinProcs,
  14. {$ENDIF}
  15.   Classes, Controls, IvMulti, IvDictio;
  16.  
  17. {$IFNDEF WIN32}
  18. const
  19.   WM_CTLCOLORDLG = $0136;
  20.  
  21. type
  22.   UINT = Word;
  23.   WPARAM = Word;
  24.   LPARAM = Longint;
  25. {$ENDIF}
  26.  
  27. type
  28.   TIvDialogModule = class(TIvModule)
  29.   protected
  30.     procedure Loaded; override;
  31.  
  32.   public
  33.     procedure TranslateDialog(handle: HWnd);
  34.  
  35.     class function AddDialogClass(dialog: TClass): Boolean;
  36.     class function RemoveDialogClass(dialog: TClass): Boolean;
  37.   end;
  38.  
  39. function IvCommonDialogProc(
  40.   handle: HWND;
  41.   msg: UINT;
  42.   wParam: WPARAM;
  43.   lParam: LPARAM): Longint; {$IFDEF WIN32}stdcall{$ELSE}export{$ENDIF};
  44.  
  45. implementation
  46.  
  47. uses
  48. {$IFDEF WIN32}
  49.   CommCtrl,
  50. {$ENDIF}
  51. {$IFDEF IVWIDE}
  52.   ExtDlgs,
  53. {$ENDIF}
  54.   SysUtils, Messages, Forms, Dialogs;
  55.  
  56. type
  57.   PPointer = ^Pointer;
  58.  
  59. {$IFDEF WIN32}
  60.   {$IFDEF IVWIDE}
  61.   PIvToolTipTextW = PToolTipTextW;
  62.   {$ELSE}
  63.   { The COMMDTRL.PAS in Delphi 2 and C++Builder 1 has an error }
  64.  
  65.   PIvToolTipTextW = ^TIvToolTipTextW;
  66.   TIvToolTipTextW = packed record
  67.     hdr: TNMHDR;
  68.     lpszText: PWideChar;
  69.     szText: array[0..79] of WideChar;
  70.     hinst: THandle;
  71.     uFlags: UINT;
  72.   end;
  73.   {$ENDIF}
  74. {$ENDIF}
  75.  
  76.   TIvFindDialog = class(TFindDialog)
  77.   protected
  78. {$IFDEF IVWIDE}
  79.     function MessageHook(var msg: TMessage): Boolean; override;
  80. {$ELSE}
  81.     function Message(var msg: TMessage): Boolean; override;
  82. {$ENDIF}
  83.   end;
  84.  
  85.   TIvCommonDialog = class(TCommonDialog)
  86.   protected
  87. {$IFDEF IVWIDE}
  88.     function MessageHook(var msg: TMessage): Boolean; override;
  89. {$ELSE}
  90.     function Message(var msg: TMessage): Boolean; override;
  91. {$ENDIF}
  92.   end;
  93.  
  94. var
  95.   FDictionary: TIvDictionary;
  96.   FDialog: TCommonDialog;
  97.   {FParent: HWnd;}
  98.   FClosing: Boolean;
  99.   FOldDialogProc: Longint;
  100.   FOffset, FCounter: Integer;
  101.   FCommonModule: TIvDialogModule;
  102.   FRegisteredDialogs, FOriginalDialogProcs: TList;
  103. {$IFDEF WIN32}
  104.   FButtonProc: TFarProc;
  105. {$ELSE}
  106.   FOldExitProc: Pointer;
  107. {$ENDIF}
  108.  
  109.  
  110. { Centers the window to the center of screen or parent }
  111.  
  112. {
  113. procedure CenterWindow(wnd: HWnd);
  114. var
  115.   rect, parentRect: TRect;
  116. begin
  117.   GetWindowRect(wnd, rect);
  118.   if FParent = 0 then
  119.   begin
  120.     SetWindowPos(
  121.       wnd,
  122.       0,
  123.       (GetSystemMetrics(SM_CXSCREEN) - (rect.Right - rect.Left)) div 2,
  124.       (GetSystemMetrics(SM_CYSCREEN) - (rect.Bottom - rect.Top)) div 2,
  125.       0,
  126.       0,
  127.       SWP_NOACTIVATE or SWP_NOSIZE or SWP_NOZORDER);
  128.   end
  129.   else
  130.   begin
  131.     GetWindowRect(FParent, parentRect);
  132.     SetWindowPos(
  133.       wnd,
  134.       0,
  135.       parentRect.Left + (parentRect.Right - parentRect.Left - (rect.Right - rect.Left)) div 2,
  136.       parentRect.Top + (parentRect.Bottom - parentRect.Top - (rect.Bottom - rect.Top)) div 2,
  137.       0,
  138.       0,
  139.       SWP_NOACTIVATE or SWP_NOSIZE or SWP_NOZORDER);
  140.   end;
  141. end;
  142. }
  143.  
  144. function IvCommonDialogProc(
  145.   handle: HWND;
  146.   msg: UINT;
  147.   wParam: WPARAM;
  148.   lParam: LPARAM): LongInt;
  149. {$IFDEF WIN32}
  150. var
  151.   ttt: PIvToolTipTextW;
  152. {$ENDIF}
  153. begin
  154.   Result := 1;
  155.   if (msg <> WM_USER + $12C) and (FOldDialogProc <> 0) then
  156.     Result := CallWindowProc(Pointer(FOldDialogProc), handle, msg, wParam, lParam);
  157.  
  158.   case msg of
  159. {$IFDEF WIN32}
  160.     WM_NOTIFY:
  161.     begin
  162.       if PNMHDR(LParam).code = TTN_NEEDTEXTW then
  163.       begin
  164.         ttt := PIvToolTipTextW(LParam);
  165.         case ttt^.hdr.idFrom of
  166.           40961: IvWStrPCopy(
  167.             ttt^.szText,
  168.             IvStrToWStr(FDictionary.Translate('Up One Level'), FDictionary.LanguageData.CodePage));
  169.  
  170.           40962: IvWStrPCopy(
  171.             ttt^.szText,
  172.             IvStrToWStr(FDictionary.Translate('Create New Folder'), FDictionary.LanguageData.CodePage));
  173.  
  174.           40963: IvWStrPCopy(
  175.             ttt^.szText,
  176.             IvStrToWStr(FDictionary.Translate('List'), FDictionary.LanguageData.CodePage));
  177.  
  178.           40964: IvWStrPCopy(
  179.             ttt^.szText,
  180.             IvStrToWStr(FDictionary.Translate('Details'), FDictionary.LanguageData.CodePage));
  181.         end;
  182.         Result := 0;
  183.         Exit;
  184.       end;
  185.     end;
  186. {$ENDIF}
  187.  
  188.     WM_CTLCOLORDLG,
  189.     WM_ACTIVATE:
  190.       FCommonModule.TranslateDialog(handle);
  191.  
  192.     WM_COMMAND:
  193. {$IFDEF WIN32}
  194.       if (LongRec(wParam).Lo = 1025) or (LongRec(wParam).Lo = 1024) then
  195. {$ELSE}
  196.       if (wParam = 1025) or (wParam = 1024) then
  197. {$ENDIF}
  198.       begin
  199.         FCommonModule.TranslateDialog(Handle);
  200.       end;
  201.  
  202.     WM_DESTROY,
  203.     WM_CLOSE:
  204.       if FOldDialogProc <> 0 then
  205.       begin
  206.         FClosing := True;
  207.         SetWindowLong(handle, GWL_WNDPROC, FOldDialogProc);
  208.         FOldDialogProc := 0;
  209.       end;
  210.   end;
  211. end;
  212.  
  213.  
  214. { TIvFindDialog }
  215.  
  216. {$IFDEF IVWIDE}
  217. function TIvFindDialog.MessageHook(var msg: TMessage):Boolean;
  218. {$ELSE}
  219. function TIvFindDialog.Message(var msg: TMessage):Boolean;
  220. {$ENDIF}
  221. begin
  222. {$IFDEF IVWIDE}
  223.   Result:= inherited MessageHook(msg);
  224. {$ELSE}
  225.   Result:= inherited Message(msg);
  226. {$ENDIF}
  227.  
  228.   case msg.Msg of
  229.     WM_CREATE:
  230.       FClosing := False;
  231.  
  232.     WM_KILLFOCUS:
  233.       if (FOldDialogProc = 0) and not FClosing then
  234.       begin
  235.         FDialog := Self;
  236.         FOldDialogProc :=
  237.           SetWindowLong(Msg.WParam, GWL_WNDPROC, LongInt(@IvCommonDialogProc));
  238.       end;
  239.   end;
  240. end;
  241.  
  242.  
  243. { TIvCommonDialog }
  244.  
  245. {$IFDEF IVWIDE}
  246. function TIvCommonDialog.MessageHook(var msg: TMessage): Boolean;
  247. {$ELSE}
  248. function TIvCommonDialog.Message(var msg: TMessage): Boolean;
  249. {$ENDIF}
  250. var
  251.   h: HWnd;
  252. begin
  253. {$IFDEF IVWIDE}
  254.   Result:= inherited MessageHook(msg);
  255. {$ELSE}
  256.   Result:= inherited Message(msg);
  257. {$ENDIF}
  258.  
  259.   case msg.Msg of
  260.     { Sets the windows hook. }
  261.  
  262.     WM_WINDOWPOSCHANGED:
  263.       if FOldDialogProc = 0 then
  264.       begin
  265.         FClosing := False;
  266.         FDialog := Self;
  267.         h := GetActiveWindow;
  268.         if (Owner = nil) or (h <> TForm(Owner).Handle) then
  269.           FOldDialogProc :=
  270.             SetWindowLong(h, GWL_WNDPROC, LongInt(@IvCommonDialogProc));
  271.       end;
  272.  
  273.     { Sets the windows hook in the case of color dialog. }
  274.  
  275.     WM_ENTERIDLE:
  276.       if (FOldDialogProc = 0) and Self.InheritsFrom(TColorDialog) then
  277.       begin
  278.         FClosing := False;
  279.         FDialog := Self;
  280.         h := GetActiveWindow;
  281.         if (Owner = nil) or (h <> TForm(Owner).Handle) then
  282.         begin
  283.           FOldDialogProc :=
  284.             SetWindowLong(h, GWL_WNDPROC, LongInt(@IvCommonDialogProc));
  285.           SendMessage(h, WM_ACTIVATE, 0, 0);
  286.         end;
  287.       end;
  288.   end;
  289. end;
  290.  
  291.  
  292. { Translates the open dialog }
  293.  
  294. function TranslateOpenDialog(wnd: HWnd; reserved: LPARAM): Bool; {$IFDEF WIN32}stdcall;{$ELSE}export;{$ENDIF}
  295. begin
  296.   Result := True;
  297.   if wnd = 0 then
  298.     Exit;
  299.  
  300.   { Translates the window text }
  301.  
  302. {$IFDEF WIN32}
  303.   case GetWindowLong(wnd, GWL_ID) of
  304. {$ELSE}
  305.   case GetWindowWord(wnd, GWW_ID) of
  306. {$ENDIF}
  307.     1: FDictionary.TranslateWindow(wnd, 'OK', True);
  308.     2: FDictionary.TranslateWindow(wnd, 'Cancel', True);
  309.     1037: FDictionary.TranslateWindow(wnd, 'Net&work...', True);
  310.     1038: FDictionary.TranslateWindow(wnd, '&Help', True);
  311.     1040: FDictionary.TranslateWindow(wnd, '&Read only', True);
  312.     1089: FDictionary.TranslateWindow(wnd, 'List files of &type:', True);
  313.     1090: FDictionary.TranslateWindow(wnd, 'File &name:', True);
  314.     1091: FDictionary.TranslateWindow(wnd, 'Dri&ves:', True);
  315.     65535: FDictionary.TranslateWindow(wnd, '&Folders:', True);
  316.   end;
  317.  
  318.   { Translates the child controls }
  319.  
  320.   EnumChildWindows(wnd, @TranslateOpenDialog, 0);
  321. end;
  322.  
  323.  
  324. { Translates the explorer open dialog }
  325.  
  326. {$IFDEF WIN32}
  327. function TranslateExplorerOpenDialog(wnd: HWnd; reserved: Integer): Bool; stdcall;
  328. var
  329.   i, count: Integer;
  330.   buffer: array[0..255] of Char;
  331.   str: String;
  332.   headerItem: THDItem;
  333. begin
  334.   Result := True;
  335.  
  336.   { Translates the window text }
  337.  
  338.   GetClassName(wnd, buffer, SizeOf(buffer));
  339.   if buffer = WC_HEADER then
  340.   begin
  341.     { Translates a Header control }
  342.  
  343.     count := Header_GetItemCount(wnd);
  344.     for i := 0 to count - 1 do
  345.     begin
  346.       headerItem.mask := HDI_TEXT;
  347.       headerItem.pszText := buffer;
  348.       headerItem.cchTextMax := SizeOf(buffer);
  349.       Header_GetItem(wnd, i, headerItem);
  350.  
  351.       case i of
  352.         0: str := FDictionary.Translate('Name');
  353.         1: str := FDictionary.Translate('Size');
  354.         2: str := FDictionary.Translate('Type');
  355.         3: str := FDictionary.Translate('Modified');
  356.         4: str := FDictionary.Translate('Attributes');
  357.       else
  358.         str := FDictionary.Translate(headerItem.pszText);
  359.       end;
  360.  
  361.       if str <> buffer then
  362.       begin
  363.         headerItem.pszText := PChar(str);
  364.         Header_SetItem(wnd, i, headerItem);
  365.       end;
  366.     end;
  367.   end
  368.   else
  369.   begin
  370.     case GetWindowLong(wnd, GWL_ID) of
  371.       1: FDictionary.TranslateWindow(wnd, '&Open', True);
  372.       2: FDictionary.TranslateWindow(wnd, 'Cancel', True);
  373.       1038: FDictionary.TranslateWindow(wnd, '&Help', True);
  374.       1040: FDictionary.TranslateWindow(wnd, 'Open as &read-only', True);
  375.       1089: FDictionary.TranslateWindow(wnd, 'Files of &type:', True);
  376.       1090: FDictionary.TranslateWindow(wnd, 'File &name:', True);
  377.       1091: FDictionary.TranslateWindow(wnd, 'Look &in:', True);
  378.     end;
  379.   end;
  380.  
  381.   { Translates the child controls }
  382.  
  383.   EnumChildWindows(wnd, @TranslateExplorerOpenDialog, 0);
  384. end;
  385. {$ENDIF}
  386.  
  387.  
  388. { Translates the save dialog }
  389.  
  390. {$IFDEF WIN32}
  391. function IvButtonProc(wnd: HWnd; msg: UINT; wParam: WPARAM; lParam: LPARAM): Integer; stdcall;
  392. begin
  393.   if msg <> WM_SETTEXT then
  394.     Result := CallWindowProc(FButtonProc, wnd, msg, wParam, lParam)
  395.   else
  396.     Result := Integer(True);
  397. end;
  398.  
  399. function TranslateExplorerSaveDialog(wnd: HWnd; reserved: Integer): Bool; stdcall;
  400. const
  401.   TEST_C = 'test';
  402. var
  403.   i, count: Integer;
  404.   buffer: array[0..255] of Char;
  405.   str: String;
  406.   headerItem: THDItem;
  407. begin
  408.   Result := True;
  409.  
  410.   { Translates the window text }
  411.  
  412.   GetClassName(wnd, buffer, SizeOf(buffer));
  413.   if buffer = WC_HEADER then
  414.   begin
  415.     { Translates a Header control }
  416.  
  417.     count := Header_GetItemCount(wnd);
  418.     for i := 0 to count - 1 do
  419.     begin
  420.       headerItem.mask := HDI_TEXT;
  421.       headerItem.pszText := buffer;
  422.       headerItem.cchTextMax := SizeOf(buffer);
  423.       Header_GetItem(wnd, i, headerItem);
  424.  
  425.       case i of
  426.         0: str := FDictionary.Translate('Name');
  427.         1: str := FDictionary.Translate('Size');
  428.         2: str := FDictionary.Translate('Type');
  429.         3: str := FDictionary.Translate('Modified');
  430.         4: str := FDictionary.Translate('Attributes');
  431.       else
  432.         str := FDictionary.Translate(headerItem.pszText);
  433.       end;
  434.  
  435.       if str <> buffer then
  436.       begin
  437.         headerItem.pszText := PChar(str);
  438.         Header_SetItem(wnd, i, headerItem);
  439.       end;
  440.     end;
  441.   end
  442.   else
  443.   begin
  444.     case GetWindowLong(wnd, GWL_ID) of
  445.       1:
  446.       begin
  447.         FDictionary.TranslateWindow(wnd, '&Save', True);
  448.         if not Assigned(FButtonProc) then
  449.         begin
  450.           FButtonProc := TFarProc(GetWindowLong(wnd, GWL_WNDPROC));
  451.           SetWindowLong(wnd, GWL_WNDPROC, Integer(@IvButtonProc));
  452.         end;
  453.       end;
  454.  
  455.       2: FDictionary.TranslateWindow(wnd, 'Cancel', True);
  456.       1038: FDictionary.TranslateWindow(wnd, '&Help', True);
  457.       1040: FDictionary.TranslateWindow(wnd, 'Open as &read-only', True);
  458.       1089: FDictionary.TranslateWindow(wnd, 'Save as &type:', True);
  459.       1090: FDictionary.TranslateWindow(wnd, 'File &name:', True);
  460.       1091: FDictionary.TranslateWindow(wnd, 'Save &in:', True);
  461.     end;
  462.   end;
  463.  
  464.   { Translates the child controls }
  465.  
  466.   EnumChildWindows(wnd, @TranslateExplorerSaveDialog, 0);
  467. end;
  468. {$ENDIF}
  469.  
  470.  
  471. { Color dialog }
  472.  
  473. function TranslateColorDialog(wnd: HWnd; reserved: LPARAM): Bool; {$IFDEF WIN32}stdcall;{$ELSE}export;{$ENDIF}
  474. begin
  475.   Result := True;
  476.  
  477.   { Translates the window text }
  478.  
  479. {$IFDEF WIN32}
  480.   case GetWindowLong(wnd, GWL_ID) of
  481. {$ELSE}
  482.   case GetWindowWord(wnd, GWW_ID) of
  483. {$ENDIF}
  484.     0: FDictionary.TranslateWindow(wnd, 'Color', False);
  485.     1: FDictionary.TranslateWindow(wnd, 'OK', True);
  486.     2: FDictionary.TranslateWindow(wnd, 'Cancel', True);
  487.     712: FDictionary.TranslateWindow(wnd, '&Add to Custom Colors', True);
  488.     719: FDictionary.TranslateWindow(wnd, '&Define Custom Colors >>', True);
  489.     723: FDictionary.TranslateWindow(wnd, 'Hu&e:', True);
  490.     724: FDictionary.TranslateWindow(wnd, '&Sat:', True);
  491.     725: FDictionary.TranslateWindow(wnd, '&Lum:', True);
  492.     726: FDictionary.TranslateWindow(wnd, '&Red:', True);
  493.     727: FDictionary.TranslateWindow(wnd, '&Green:', True);
  494.     728: FDictionary.TranslateWindow(wnd, 'Bl&ue:', True);
  495.     730: FDictionary.TranslateWindow(wnd, 'Color', True);
  496.     731: FDictionary.TranslateWindow(wnd, '|S&olid', True);
  497.     1038: FDictionary.TranslateWindow(wnd, '&Help', True);
  498.     65535:
  499.       begin
  500.         case FCounter of
  501.           0: FDictionary.TranslateWindow(wnd, '&Basic colors:', True);
  502.           1: FDictionary.TranslateWindow(wnd, '&Custom colors:', True);
  503.         end;
  504.         Inc(FCounter);
  505.       end;
  506.   end;
  507.  
  508.   { Translates the child controls }
  509.  
  510.   EnumChildWindows(wnd, @TranslateColorDialog, 0);
  511. end;
  512.  
  513.  
  514. { Font }
  515.  
  516. function TranslateFontDialog(wnd: HWnd; reserved: LPARAM): Bool; {$IFDEF WIN32}stdcall;{$ELSE}export;{$ENDIF}
  517. begin
  518.   Result := True;
  519.  
  520.   { Translates the window text }
  521.  
  522. {$IFDEF WIN32}
  523.   case GetWindowLong(wnd, GWL_ID) of
  524. {$ELSE}
  525.   case GetWindowWord(wnd, GWW_ID) of
  526. {$ENDIF}
  527.     0: FDictionary.TranslateWindow(wnd, 'Font', False);
  528.     1: FDictionary.TranslateWindow(wnd, 'OK', True);
  529.     2: FDictionary.TranslateWindow(wnd, 'Cancel', True);
  530.     1026: FDictionary.TranslateWindow(wnd, '&Apply', True);
  531.     1038: FDictionary.TranslateWindow(wnd, '&Help', True);
  532.     1040: FDictionary.TranslateWindow(wnd, 'Stri&keout', True);
  533.     1041: FDictionary.TranslateWindow(wnd, '&Underline', True);
  534.     1072: FDictionary.TranslateWindow(wnd, 'Effects', True);
  535.     1073: FDictionary.TranslateWindow(wnd, 'Sample', True);
  536.     1088: FDictionary.TranslateWindow(wnd, '&Font:', True);
  537.     1089: FDictionary.TranslateWindow(wnd, 'Font st&yle:', True);
  538.     1090: FDictionary.TranslateWindow(wnd, '&Size:', True);
  539.     1091: FDictionary.TranslateWindow(wnd, '&Color:', True);
  540.     1094: FDictionary.TranslateWindow(wnd, 'Sc&ript:', True);
  541.   end;
  542.  
  543.   { Translates the child controls }
  544.  
  545.   EnumChildWindows(wnd, @TranslateFontDialog, 0);
  546. end;
  547.  
  548.  
  549. { Print and Priner Setup dialogs }
  550.  
  551. function TranslatePrintDialog(wnd: HWnd; reserved: LPARAM): Bool; {$IFDEF WIN32}stdcall;{$ELSE}export;{$ENDIF}
  552. begin
  553.   Result := True;
  554.  
  555.   { Translates the window text }
  556.  
  557. {$IFDEF WIN32}
  558.   case GetWindowLong(wnd, GWL_ID) of
  559. {$ELSE}
  560.   case GetWindowWord(wnd, GWW_ID) of
  561. {$ENDIF}
  562.     0: FDictionary.TranslateWindow(wnd, 'Print', False);
  563.     1: FDictionary.TranslateWindow(wnd, 'OK', True);
  564.     2: FDictionary.TranslateWindow(wnd, 'Cancel', True);
  565.  
  566.     1025: FDictionary.TranslateWindow(wnd, '&Properties', True);
  567.     1040: FDictionary.TranslateWindow(wnd, 'Print to fi&le', True);
  568.     1041: FDictionary.TranslateWindow(wnd, 'C&ollate', True);
  569.     1056: FDictionary.TranslateWindow(wnd, '&All', True);
  570.     1057: FDictionary.TranslateWindow(wnd, '&Selection', True);
  571.     1058: FDictionary.TranslateWindow(wnd, 'Pa&ges', True);
  572.     1072: FDictionary.TranslateWindow(wnd, 'Print range', True);
  573.     1073: FDictionary.TranslateWindow(wnd, 'Copies', True);
  574.     1075: FDictionary.TranslateWindow(wnd, 'Printer', True);
  575.     1089: FDictionary.TranslateWindow(wnd, '&from:', True);
  576.     1090: FDictionary.TranslateWindow(wnd, '&to:', True);
  577.     1092: FDictionary.TranslateWindow(wnd, 'Number of &copies:', True);
  578.     1093: FDictionary.TranslateWindow(wnd, '&Name:', True);
  579.     1094: FDictionary.TranslateWindow(wnd, 'Type:', True);
  580.     1095: FDictionary.TranslateWindow(wnd, 'Status:', True);
  581.     1096: FDictionary.TranslateWindow(wnd, 'Comment:', True);
  582.     1097: FDictionary.TranslateWindow(wnd, 'Where:', True);
  583.   end;
  584.  
  585.   { Translates the child controls }
  586.  
  587.   EnumChildWindows(wnd, @TranslatePrintDialog, 0);
  588. end;
  589.  
  590. function TranslatePrinterSetupDialog(wnd: HWnd; reserved: LPARAM): Bool; {$IFDEF WIN32}stdcall;{$ELSE}export;{$ENDIF}
  591. begin
  592.   Result := True;
  593.  
  594.   { Translates the window text }
  595.  
  596. {$IFDEF WIN32}
  597.   case GetWindowLong(wnd, GWL_ID) of
  598. {$ELSE}
  599.   case GetWindowWord(wnd, GWW_ID) of
  600. {$ENDIF}
  601.     0: FDictionary.TranslateWindow(wnd, 'Print Setup', False);
  602.     1: FDictionary.TranslateWindow(wnd, 'OK', True);
  603.     2: FDictionary.TranslateWindow(wnd, 'Cancel', True);
  604.  
  605.     1025: FDictionary.TranslateWindow(wnd, '&Properties', True);
  606.     1037: FDictionary.TranslateWindow(wnd, 'Net&work...', True);
  607.     1056: FDictionary.TranslateWindow(wnd, 'P&ortrait', True);
  608.     1057: FDictionary.TranslateWindow(wnd, 'L&andscape', True);
  609.     1072: FDictionary.TranslateWindow(wnd, 'Orientation', True);
  610.     1073: FDictionary.TranslateWindow(wnd, 'Paper', True);
  611.     1075: FDictionary.TranslateWindow(wnd, 'Printer', True);
  612.     1089: FDictionary.TranslateWindow(wnd, 'Si&ze:', True);
  613.     1090: FDictionary.TranslateWindow(wnd, '&Source:', True);
  614.     1093: FDictionary.TranslateWindow(wnd, '&Name:', True);
  615.     1094: FDictionary.TranslateWindow(wnd, 'Type:', True);
  616.     1095: FDictionary.TranslateWindow(wnd, 'Status:', True);
  617.     1096: FDictionary.TranslateWindow(wnd, 'Comment:', True);
  618.     1097: FDictionary.TranslateWindow(wnd, 'Where:', True);
  619.   end;
  620.  
  621.   { Translates the child controls }
  622.  
  623.   EnumChildWindows(wnd, @TranslatePrinterSetupDialog, 0);
  624. end;
  625.  
  626.  
  627. { Find }
  628.  
  629. function TranslateFindDialog(wnd: HWnd; reserved: LPARAM): Bool; {$IFDEF WIN32}stdcall;{$ELSE}export;{$ENDIF}
  630. begin
  631.   Result := True;
  632.  
  633.   { Translates the window text }
  634.  
  635. {$IFDEF WIN32}
  636.   case GetWindowLong(wnd, GWL_ID) of
  637. {$ELSE}
  638.   case GetWindowWord(wnd, GWW_ID) of
  639. {$ENDIF}
  640.     0: FDictionary.TranslateWindow(wnd, 'Find', False);
  641.     1: FDictionary.TranslateWindow(wnd, '&Find Next', True);
  642.     2: FDictionary.TranslateWindow(wnd, 'Cancel', True);
  643.     1038: FDictionary.TranslateWindow(wnd, '&Help', True);
  644.     1040: FDictionary.TranslateWindow(wnd, 'Match &whole word only', True);
  645.     1041: FDictionary.TranslateWindow(wnd, 'Match &case', True);
  646.     1056: FDictionary.TranslateWindow(wnd, '&Up', True);
  647.     1057: FDictionary.TranslateWindow(wnd, '&Down', True);
  648.     1072: FDictionary.TranslateWindow(wnd, 'Direction', True);
  649.     65535: FDictionary.TranslateWindow(wnd, 'Fi&nd what:', True);
  650.   end;
  651.  
  652.   { Translates the child controls }
  653.  
  654.   EnumChildWindows(wnd, @TranslateFindDialog, 0);
  655. end;
  656.  
  657.  
  658. { Replace }
  659.  
  660. function TranslateReplaceDialog(wnd: HWnd; reserved: LPARAM): Bool; {$IFDEF WIN32}stdcall;{$ELSE}export;{$ENDIF}
  661. begin
  662.   Result := True;
  663.  
  664.   { Translates the window text }
  665.  
  666. {$IFDEF WIN32}
  667.   case GetWindowLong(wnd, GWL_ID) of
  668. {$ELSE}
  669.   case GetWindowWord(wnd, GWW_ID) of
  670. {$ENDIF}
  671.     0: FDictionary.TranslateWindow(wnd, 'Replace', False);
  672.     1: FDictionary.TranslateWindow(wnd, '&Find Next', True);
  673.     2: FDictionary.TranslateWindow(wnd, 'Cancel', True);
  674.     1038: FDictionary.TranslateWindow(wnd, '&Help', True);
  675.     1024: FDictionary.TranslateWindow(wnd, '&Replace', True);
  676.     1025: FDictionary.TranslateWindow(wnd, 'Replace &All', True);
  677.     1040: FDictionary.TranslateWindow(wnd, 'Match &whole word only', True);
  678.     1041: FDictionary.TranslateWindow(wnd, 'Match &case', True);
  679.     65535:
  680.       begin
  681.         case FCounter of
  682.           0: FDictionary.TranslateWindow(wnd, 'Fi&nd what:', True);
  683.           1: FDictionary.TranslateWindow(wnd, 'Re&place with:', True);
  684.         end;
  685.         Inc(FCounter);
  686.       end;
  687.   end;
  688.  
  689.   { Translates the child controls }
  690.  
  691.   EnumChildWindows(wnd, @TranslateReplaceDialog, 0);
  692. end;
  693.  
  694.  
  695. { TIvDialogModule }
  696.  
  697. procedure TIvDialogModule.TranslateDialog(handle: HWnd);
  698.  
  699.   procedure TranslateOpenCaption;
  700.   begin
  701.     if TOpenDialog(FDialog).Title = '' then
  702.       FDictionary.TranslateWindow(handle, 'Open', False)
  703.   end;
  704.  
  705.   procedure TranslateSaveCaption;
  706.   begin
  707.     if TOpenDialog(FDialog).Title = '' then
  708.       FDictionary.TranslateWindow(handle, 'Save As', False)
  709.   end;
  710.  
  711. begin
  712.   FDictionary := GetDefaultDictionary;
  713.   FCounter := 0;
  714.  
  715.   { Translates the active dialog }
  716.  
  717.   if (FDialog is TSaveDialog)
  718. {$IFDEF IVWIDE}
  719.     or (FDialog is TSavePictureDialog)
  720. {$ENDIF}
  721.   then
  722.   begin
  723. {$IFDEF WIN32}
  724.     if not (ofOldStyleDialog in TOpenDialog(FDialog).Options) then
  725.       TranslateExplorerSaveDialog(handle, 0)
  726.     else
  727. {$ENDIF}
  728.       TranslateOpenDialog(handle, 0);
  729.     TranslateSaveCaption;
  730.   end
  731.   else if (FDialog is TOpenDialog)
  732. {$IFDEF IVWIDE}
  733.     or (FDialog is TOpenPictureDialog)
  734. {$ENDIF}
  735.   then
  736.   begin
  737. {$IFDEF WIN32}
  738.     if not (ofOldStyleDialog in TOpenDialog(FDialog).Options) then
  739.       TranslateExplorerOpenDialog(handle, 0)
  740.     else
  741. {$ENDIF}
  742.       TranslateOpenDialog(handle, 0);
  743.     TranslateOpenCaption;
  744.   end
  745.   else if FDialog is TColorDialog then
  746.     TranslateColorDialog(handle, 0)
  747.   else if FDialog is TFontDialog then
  748.     TranslateFontDialog(handle, 0)
  749.   else if FDialog is TReplaceDialog then
  750.     TranslateReplaceDialog(handle, 0)
  751.   else if FDialog is TFindDialog then
  752.     TranslateFindDialog(handle, 0)
  753.   else if FDialog is TPrintDialog then
  754.     TranslatePrintDialog(handle, 0)
  755.   else if FDialog is TPrinterSetupDialog then
  756.     TranslatePrinterSetupDialog(handle, 0)
  757. end;
  758.  
  759. class function TIvDialogModule.AddDialogClass(dialog: TClass): Boolean;
  760. var
  761.   proc: PPointer;
  762.   protect: Longint;
  763. {$IFNDEF WIN32}
  764.   sel, seg: Word;
  765. {$ENDIF}
  766. begin
  767.   { If the given class is null or not a common dialog or the dialog has already
  768.     been registered, exists. }
  769.  
  770.   if (dialog = nil) or
  771.     not dialog.InheritsFrom(TCommonDialog) or
  772.     (FRegisteredDialogs.IndexOf(Pointer(dialog)) <> -1) then
  773.   begin
  774.     Result := False;
  775.     Exit;
  776.   end;
  777.  
  778.   { Calculates the offset of the message hook variable in the common dialog }
  779.  
  780.   if FOffset = 0 then
  781.   begin
  782. {$IFDEF IVWIDE}
  783.     while (@TIvCommonDialog.MessageHook <> PPointer(LongInt(TIvCommonDialog) + FOffset)^) do
  784. {$ELSE}
  785.     while (@TIvCommonDialog.Message <> PPointer(LongInt(TIvCommonDialog) + FOffset)^) do
  786. {$ENDIF}
  787.     begin
  788.       Inc(FOffset);
  789.     end;
  790.   end;
  791.  
  792.   { Replaces the VCL standard message function with ML one. }
  793.  
  794.   proc := PPointer(Longint(dialog) + Longint(FOffset));
  795.   FRegisteredDialogs.Add(Pointer(dialog));
  796.   FOriginalDialogProcs.Add(proc^);
  797. {$IFDEF WIN32}
  798.   VirtualProtect(Proc, 4, PAGE_READWRITE, @protect);
  799. {$ELSE}
  800.   seg := PtrRec(proc).Seg;
  801.   GlobalPageLock(seg);
  802.   sel := AllocSelector(seg);
  803.   PrestoChangoSelector(seg, sel);
  804.   proc := Ptr(sel, PtrRec(proc).Ofs);
  805. {$ENDIF}
  806.  
  807. {$IFDEF IVWIDE}
  808.   if (dialog.InheritsFrom(TFindDialog)) then
  809.     proc^ := @TIvFindDialog.MessageHook
  810.   else
  811.     proc^ := @TIvCommonDialog.MessageHook;
  812. {$ELSE}
  813.   if (dialog.InheritsFrom(TFindDialog)) then
  814.     proc^ := @TIvFindDialog.Message
  815.   else
  816.     proc^ := @TIvCommonDialog.Message;
  817. {$ENDIF}
  818.  
  819. {$IFDEF WIN32}
  820.   VirtualProtect(proc, 4, protect, @protect);
  821. {$ELSE}
  822.   GlobalPageUnlock(seg);
  823. {$ENDIF}
  824.  
  825.   Result := True;
  826. end;
  827.  
  828. class function TIvDialogModule.RemoveDialogClass(dialog: TClass): Boolean;
  829. var
  830.   proc: PPointer;
  831.   protect, index: LongInt;
  832. {$IFNDEF WIN32}
  833.   sel, seg: Word;
  834. {$ENDIF}
  835. begin
  836.   index := FRegisteredDialogs.IndexOf(Pointer(dialog));
  837.   if index = -1 then
  838.   begin
  839.     Result := False;
  840.     Exit;
  841.   end;
  842.  
  843.   proc := PPointer(LongInt(dialog) + FOffset);
  844.  
  845. {$IFDEF WIN32}
  846.   VirtualProtect(proc, 4, PAGE_READWRITE, @protect);
  847. {$ELSE}
  848.   seg := PtrRec(Proc).Seg;
  849.   GlobalPageLock(seg);
  850.   sel := AllocSelector(seg);
  851.   PrestoChangoSelector(seg, sel);
  852.   proc := Ptr(sel, PtrRec(proc).Ofs);
  853. {$ENDIF}
  854.  
  855.   proc^ := FOriginalDialogProcs.Items[Index];
  856.  
  857. {$IFDEF WIN32}
  858.   VirtualProtect(proc, 4, Protect, @protect);
  859. {$ELSE}
  860.   GlobalPageUnlock(seg);
  861. {$ENDIF}
  862.  
  863.   FRegisteredDialogs.Delete(index);
  864.   FRegisteredDialogs.Pack;
  865.   FOriginalDialogProcs.Delete(index);
  866.   FOriginalDialogProcs.Pack;
  867.  
  868.   Result := True;
  869. end;
  870.  
  871. procedure TIvDialogModule.Loaded;
  872. var
  873.   i: Integer;
  874. begin
  875.   inherited Loaded;
  876.   if not (csDesigning in ComponentState) then
  877.   begin
  878.     { Registers the standard common dialog components of VCL to the module }
  879.  
  880.     TIvDialogModule.AddDialogClass(TOpenDialog);
  881.     TIvDialogModule.AddDialogClass(TSaveDialog);
  882. {$IFDEF IVWIDE}
  883.     TIvDialogModule.AddDialogClass(TOpenPictureDialog);
  884.     TIvDialogModule.AddDialogClass(TSavePictureDialog);
  885. {$ENDIF}
  886.     TIvDialogModule.AddDialogClass(TColorDialog);
  887.     TIvDialogModule.AddDialogClass(TSaveDialog);
  888.     TIvDialogModule.AddDialogClass(TPrintDialog);
  889.     TIvDialogModule.AddDialogClass(TPrinterSetupDialog);
  890.     TIvDialogModule.AddDialogClass(TFindDialog);
  891.     TIvDialogModule.AddDialogClass(TReplaceDialog);
  892.  
  893.     { Registers the other common dialog components on the host form }
  894.  
  895.     for i := 0 to Owner.ComponentCount - 1 do
  896.       if Owner.Components[i] is TCommonDialog then
  897.         AddDialogClass(Owner.Components[i].ClassType);
  898.   end;
  899. end;
  900.  
  901. procedure RemoveDialogClasses;
  902. begin
  903.   while FRegisteredDialogs.Count > 0 do
  904.     TIvDialogModule.RemoveDialogClass(TClass(FRegisteredDialogs.Items[0]));
  905.   FOriginalDialogProcs.Free;
  906.   FRegisteredDialogs.Free;
  907. end;
  908.  
  909. {$IFNDEF WIN32}
  910. procedure ExitUnit; far;
  911. begin
  912.   ExitProc := FOldExitProc;
  913.   RemoveDialogClasses;
  914. end;
  915. {$ENDIF}
  916.  
  917. initialization
  918. {$IFNDEF WIN32}
  919.   FOldExitProc := ExitProc;
  920.   ExitProc := @ExitUnit;
  921. {$ENDIF}
  922.  
  923.   FOldDialogProc := 0;
  924.   FOffset := 0;
  925.   FClosing := False;
  926.   FRegisteredDialogs := TList.Create;
  927.   FOriginalDialogProcs := TList.Create;
  928. {$IFDEF WIN32}
  929. finalization
  930.   RemoveDialogClasses;
  931. {$ENDIF}
  932. end.
  933.